﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common
{
    public class ScrollingList<T> : List<T>
    {
        private int _maxCount;

        public int MaxCount
        {
            get { return _maxCount; }
            set { _maxCount = value; }
        }

        public ScrollingList(int maxCount, T initialisationValue) :
            base(maxCount)
        {
            _maxCount = maxCount;
            for (int i = 0; i < _maxCount; i++)
            {
                AddItem(initialisationValue);
            }
        }

        public ScrollingList(int maxCount) :
            base(maxCount)
        {
            _maxCount = maxCount;
        }

        public void AddItem(T item)
        {
            while (Count >= _maxCount)
                RemoveAt(0);

            Add(item);
        }
    }
}
